package TestCases;

import java.util.ArrayList;
import pos.control.PurchasedItemControl;
import pos.entity.PurchasedItem;

/**
 *
 * @author JH
 */
public class UnitTest_PurchasedItems {

    private static UnitTestOracle_OrdersAndPItems _oracle;
    
    //Constructor
    public static void RunTests() {

        _oracle = new UnitTestOracle_OrdersAndPItems();

        ArrayList<PurchasedItem> pItemList = _oracle.getOraclePItemList();

        //Test 1
        testPIPriceCalculation(pItemList);

        //Test 2
        testRepeatCalculation(pItemList);
    }

    //Test 1: Calculations for purchased items are correct
    private static void testPIPriceCalculation(ArrayList<PurchasedItem> pItemList) {

        PurchasedItemControl pItemCtrl = new PurchasedItemControl();

        ArrayList<PurchasedItem> returnList = pItemCtrl.updatePurchasedItemPriceAttributes(pItemList);

        if (_oracle.purchasedItemsAreValid(returnList) == true) {
            System.out.println("TEST PASSED: pItem price calculation TEST");
        }
        else {
            System.out.println("TEST FAIL: pItem price calculation TEST");
        }
    }

    //Test 2: Calculations for purchased items do not change
    private static void testRepeatCalculation(ArrayList<PurchasedItem> pItemList) {

        PurchasedItemControl pItemCtrl = new PurchasedItemControl();

        ArrayList<PurchasedItem> returnList = pItemCtrl.updatePurchasedItemPriceAttributes(pItemList);
        returnList = pItemCtrl.updatePurchasedItemPriceAttributes(pItemList);
        returnList = pItemCtrl.updatePurchasedItemPriceAttributes(pItemList);
        returnList = pItemCtrl.updatePurchasedItemPriceAttributes(pItemList);

        if (_oracle.purchasedItemsAreValid(returnList) == true) {
            System.out.println("TEST PASSED: pItem repeat calculation TEST");
        }
        else {
            System.out.println("TEST FAIL: pItem repeat calculation TEST");
        }
    }
}
